// pages/videolist/videolist.js  按字母查找
var shihan = require('../../../common/fetch');
var config = require('../../../common/config');
Page({
  data: {
    list: [],
    alpha: '',
    windowHeight: ''
  },
  onLoad(options) {
    var that = this
    shihan.sendRequest(config.videoall, 'GET', {}, {})
      .then(function(response) {
        that.setData({
          list: response.data.data
        });
        try {
          var res = wx.getSystemInfoSync()
          that.pixelRatio = res.pixelRatio;
          // this.apHeight = 32 / this.pixelRatio;
          // this.offsetTop = 160 / this.pixelRatio;
          that.apHeight = 16;
          // this.offsetTop = 80;
          // console.log(that.data.list);
          that.setData({
            windowHeight: res.windowHeight,
            selectorHeight: 18 * (that.data.list.length)
          })
          that.setData({
            selectorTop: (that.data.windowHeight - that.data.selectorHeight) / 2
          })
          that.offsetTop = that.data.selectorTop;
        } catch (e) {

        }
      }, function(error) {
        console.log(error);
      });
  },
  openvideo: function(e) {
    wx.navigateTo({
      url: '/pages/other/videodetail/videodetail?id=' + e.currentTarget.dataset.id
    })
  },
  handlerAlphaTap(e) {
    let {
      ap
    } = e.target.dataset;
    this.setData({
      alpha: ap
    });
  },
  handlerMove(e) {
    let {
      list
    } = this.data;
    let moveY = e.touches[0].clientY;
    let rY = moveY - this.offsetTop;
    if (rY >= 0) {
      let index = Math.ceil((rY - this.apHeight) / this.apHeight);
      console.log(index)
      if (0 <= index < list.length) {
        let nonwAp = list[index];
        nonwAp && this.setData({
          alpha: nonwAp.sh_zimu
        });
      }
    }
  }
})